package com.example.moments.starpMome;

import android.annotation.SuppressLint;
import android.app.DatePickerDialog;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

//import androidx.appcompat.app.AppCompatActivity;
//import androidx.navigation.ui.AppBarConfiguration;

//import com.example.myapplication.MainActivity;
//import com.example.myapplication.NotificationMonitorActivity;
//import com.example.myapplication.R;
//import com.example.myapplication.SmsReadActivity;
//import com.example.myapplication.adapter.ProxyAdapter;
//import com.example.myapplication.adapter.RvAdapter;
//import com.example.myapplication.databinding.ActivityMainBinding;
//import com.example.myapplication.databinding.ActivityWechatMomentsBinding;
//import com.example.myapplication.databinding.NotificationMonitorBinding;
//import com.example.myapplication.model.Moment;
//import com.example.myapplication.model.ShortMessage;
//import com.example.myapplication.observer.SMSContentObserver;
//import com.example.myapplication.util.DateUtil;
//import com.example.myapplication.util.DrawUtil;
//import com.example.myapplication.util.EmailSendThread;
//import com.google.android.material.snackbar.Snackbar;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.moments.R;
import com.example.moments.adapter.ProxyAdapter;
import com.example.moments.adapter.RvAdapter;
import com.example.moments.utils.DrawUtil;

public class MomentsActivity extends AppCompatActivity {
    //    private ActivityMainBinding binding;
//    private NotificationMonitorBinding
    private RecyclerView rv;
    private static final String TAG = "MomentsActivity";
//    private AppBarConfiguration appBarConfiguration;

    private RvAdapter rvAdapter;

//    private ActivityWechatMomentsBinding binding;

    private RecyclerView.ItemDecoration itemDecoration;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

//        setButton();
        setContentView(R.layout.activity_wechat_moments);
//        binding = ActivityWechatMomentsBinding.inflate(getLayoutInflater());
//        setContentView(binding.getRoot());
//        setSupportActionBar(binding.toolbar);
//
//        setSupportActionBar(binding.toolbar);

        rv = findViewById(R.id.rv);
        setDatas();
//        Log.i(TAG," setDatas");
//        Log.i(TAG, String.valueOf(datas));

//        不设置的话 就不显示了
        /**第一步：设置布局管理器**/
        rv.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        /**第二步：添加分割线**/
        itemDecoration = new DividerItemDecoration(this, DividerItemDecoration.VERTICAL);
        rv.addItemDecoration(itemDecoration);

        /**第三步：设置适配器**/
//        rvAdapter = new RvAdapter((Context) this, datas);
        rvAdapter = new RvAdapter(this, datas);
//        AppCompatActivity 不是Context
//        rvAdapter = new RvAdapter(this.btn_add.getContext(), datas);
//        rv.setAdapter(rvAdapter);
//        setAdapter 需要设置 他的 代理
        rvAdapter.setOnItemClickListener(new RvAdapter.OnItemClickListener() {
            @Override
            public void onItemClickListener(int position, Integer data) {
                Toast.makeText(MomentsActivity.this, "点击了" + position, Toast.LENGTH_SHORT).show();
            }

        });

        setHeader(rv);

//          ivMyAvatar=findViewById(R.id.ivMyAvatar);
////          因为 没有header 的时候 是没有的
//        DrawUtil.setRoundImageDrawable(ivMyAvatar,R.drawable.miku_fang,getResources());
//        ivMyAvatar
//        setContentView(R.layout.activity_sms_read);


    }
    ImageView  ivMyAvatar;
    List<Moment> datas = new ArrayList<>();

    int lo_explore_pengyouquan_head_item= R.layout.explore_pengyouquan_head_item_starp;
    private void setHeader(RecyclerView view) {
//        RecyclerView.Adapter adapter;
//        adapter.setHasStableIds();
//       int i= R.layout.explore_pengyouquan_head_item_starp;
//        View header = LayoutInflater.from(this).inflate(R.layout.explore_pengyouquan_head_item, view, false);
//        View header = LayoutInflater.from(this).inflate(R.layout.explore_pengyouquan_head_item_starp, view, false);
        View header = LayoutInflater.from(this).inflate(lo_explore_pengyouquan_head_item, view, false);
//        rvAdapter.set(header);
//        Adapter setheader
//        rvAdapter.add

//        R.id.
//       ContactAdapter adapter = new ContactAdapter();
        ivMyAvatar= header.findViewById(R.id.ivMyAvatar);
        DrawUtil.setRoundImageDrawable(ivMyAvatar,R.drawable.miku_fang,getResources());
//        DrawUtil.ad
        ProxyAdapter proxyAdapter = new ProxyAdapter(rvAdapter);
        proxyAdapter.addHeaderView(header);
        rv.setAdapter(proxyAdapter);
//        setAdapter 需要设置 他的 代理
//        https://www.cnblogs.com/canf963/p/7681608.html
//        为什么 etAdapter(proxyAdapter)
//        而 不是 原来的 rvAdapter，这样感觉 很复杂
//        adapter 单独的一个类

    }

    void setDatas() {
//        Resources resources = getResources();
//        Moment moment = new Moment();
//        Moment.builder().
//        Moment.buil
//        Moment moment1 = new Moment();
//        moment1.
//        Moment
        for (int i = 0; i < 4; i++) {
//            new Moment(1,1);
            Moment moment = new Moment();
            moment.setId(i);
            moment.setAvatar(R.drawable.miku_fang);
            moment.setNickname("miku酱~");
            moment.setWrittenwords("这就是你的逃走线路吗");
            moment.setImgs("https://image.renlaibang.com/FiP9T9ncrNL-AH45IMhQaZgqwwSk,https://image.renlaibang.com/Fp5mQrZYnhSRoKayTsPEaBO18Wrt,https://image.renlaibang.com/Fv4GWEHOMvdMkBHz12XWxtEJMSd1,https://image.renlaibang.com/FgiOlNKk71GfgzunMvRXwi1zzIPp,https://image.renlaibang.com/FhAkT41j6Ma5wGRmYcm4MQF2NjSt,https://image.renlaibang.com/Fj8opkB-dS_Jmg-K41oWRhJQs0i0");
//            Moment moment = Moment.builder().id(i).
////                    avatar(R.drawable.ic_launcher_foreground)
////                    avatar(R.drawable.makima)
//                    avatar(R.drawable.miku_fang)
//                    .nickname("starp").writtenwords("这就是你的逃走线路吗").
//                            imgs("https://image.renlaibang.com/FiP9T9ncrNL-AH45IMhQaZgqwwSk,https://image.renlaibang.com/Fp5mQrZYnhSRoKayTsPEaBO18Wrt,https://image.renlaibang.com/Fv4GWEHOMvdMkBHz12XWxtEJMSd1,https://image.renlaibang.com/FgiOlNKk71GfgzunMvRXwi1zzIPp,https://image.renlaibang.com/FhAkT41j6Ma5wGRmYcm4MQF2NjSt,https://image.renlaibang.com/Fj8opkB-dS_Jmg-K41oWRhJQs0i0").build();
            datas.add(moment);
        }

    }


    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();

    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

}
